// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects.Exceptions;

namespace TestValidationAspects.Exceptions
{
	[TestFixture]
	public class TestValidateNotEqualException
	{
		[SetUp]
		public void SetUp()
		{
			ValidateNotEqualException.ResetMessageFormat();
		}

		[Test]
		public void Test_Constructor()
		{
			ValidateNotEqualException exception = new ValidateNotEqualException(1);
			Assert.AreEqual(1, exception.Value);
			Assert.IsFalse(exception.IgnoreCase);

			exception = new ValidateNotEqualException("test", true);
			Assert.AreEqual("test", exception.Value);
			Assert.IsTrue(exception.IgnoreCase);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Constructor_throws_for_null_string_param()
		{
			new ValidateNotEqualException(null, false);
		}

		[Test]
		public void Test_default_MessageFormat()
		{
			ValidateNotEqualException exception = new ValidateNotEqualException(1);
			Assert.AreEqual(string.Format("{0} must not equal {1}.", exception.GetValidationTargetName(), 1), ValidateNotEqualException.MessageFormat(exception));
		}

		[Test]
		public void Test_get_Message_executes_MessageFormat()
		{
			const string message = "custom message";
			ValidateNotEqualException.MessageFormat = e => message;
			Assert.AreEqual(message, new ValidateNotEqualException(1).Message);
		}

		[Test]
		public void Test_ResetMessageFormat()
		{
			const string message = "custom message";
			ValidateNotEqualException.MessageFormat = e => message;

			ValidateNotEqualException exception = new ValidateNotEqualException(1);
			Assert.AreEqual(message, exception.Message);

			ValidateNotEqualException.ResetMessageFormat();
			Assert.AreEqual(string.Format("{0} must not equal {1}.", exception.GetValidationTargetName(), 1), ValidateNotEqualException.MessageFormat(exception));
		}
	}
}